using System.Windows;

namespace SilverPop.UI.Controls
{
	public static class RectExtensions
	{
		public static Rect OffsetSafe(this Rect source, Thumbs thumb, Point offset )
		{
			double x = source.X;
			double y = source.Y;
			double w = source.Width;
			double h = source.Height;

			if( thumb == Thumbs.TopLeft || thumb == Thumbs.TopRight )
			{
				if ((h + offset.Y) > 50)
				{
					y -= offset.Y;
					h += offset.Y;
				}
			}
			if( thumb == Thumbs.BottomLeft || thumb == Thumbs.BottomRight )
			{
				if((h - offset.Y) > 50)
				{
					h -= offset.Y;
				}
			}
			if( thumb == Thumbs.TopLeft || thumb == Thumbs.BottomLeft )
			{
				if ((w + offset.X) > 50)
				{
					x -= offset.X;
					w += offset.X;
				}
			}
			if( thumb == Thumbs.TopRight || thumb == Thumbs.BottomRight )
			{
				if( (w-offset.X) > 50 )
				{
					w -= offset.X;
				}
			}

			return new Rect(x,y,w,h);
		}
	}
}